﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using CommandExecuter;
using PHPGenerator;

namespace Variables
{
    class Variable
    {
        public ArrayList names = new ArrayList();
        public ArrayList vals = new ArrayList();
        public void AddVar(string name, object val)
        {
            if (!this.ExistsVar(name))
            {
                this.names.Add(name);
                this.vals.Add(val);
            }
            
        }
        public void glov()
        {
            Console.Write(this.names.Count);
        }
        public bool ExistsVar(string name)
        {
            bool done = false;
            foreach (object nm in this.names)
            {
                if (System.Convert.ToString(nm) == name)
                    done = true;
                else
                    continue;
            }
            if (done)
                return true;
            else
                return false;
        }
        public object GetVal(string name)
        {
            int i = 0;
            
            foreach (string nm in this.names)
            {
                if (nm.ToString() == name)
                    break;
                else
                    i++;
            }
            if (i > this.names.Count - 1)
                return null;
            else
                return this.vals[i];
        }
        public void AddStartVars()
        {
            this.names.Add("#endl");
            this.vals.Add("\r\n");
        }
        public void SetVal(string name, object val)
        {
            int i = 0;
            foreach (object nm in this.names)
            {
                if (nm.ToString() == name)
                    break;
                else
                    i++;
            }
            if (i <= this.names.Count - 1)
                this.vals[i] = val;
        }
    }

    class Array
    {
        public ArrayList names = new ArrayList();
        public ArrayList arrays = new ArrayList();
        public void AddArray(string name, ArrayList items)
        {
            this.names.Add(name);
            this.arrays.Add(items);
        }
        public void SetItem(string name, object pos, object item)
        {
            int i = 0;
            foreach (object nm in this.names)
            {
                if (nm.ToString() == name)
                {
                    break;
                }
                else
                    i++;
            }
            if (i < this.names.Count-1)
            {
                (this.arrays[i] as ArrayList)[System.Convert.ToInt32(pos)] = item;
            }   
        }
        public object GetItem(string ArrayName, object pos)
        {
            int i = 0;
            foreach (object name in this.names)
            {
                if (name.ToString() == ArrayName)
                    break;
                else
                    i++;
            }
            if (i < this.names.Count)
            {
                return (this.arrays[i] as ArrayList)[System.Convert.ToInt32(pos)];
            }
            else
                return null;
        }
    }
}